package com.party.business.controller;


import java.util.Arrays;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.party.common.annotation.DataSource;
import com.party.common.annotation.Log;
import com.party.common.core.controller.BaseController;
import com.party.common.core.domain.AjaxResult;
import com.party.common.core.page.TableDataInfo;
import com.party.common.enums.BusinessType;
import com.party.common.enums.DataSourceType;
import com.party.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.party.business.domain.ExamplesWar;
import com.party.business.service.IExamplesWarService;

/**
 * 战例数据Controller
 *
 * @author ruoyi
 * @date 2025-06-24
 */
@RestController
@RequestMapping("/business/examplewar" )
public class ExamplesWarController extends BaseController {
    @Autowired
    private IExamplesWarService examplesWarService;

/**
 * 查询战例数据列表
 */
//@RequiresPermissions("business:examplewar:list")
@GetMapping("/list" )
@DataSource(value = DataSourceType.SLAVE)
    public TableDataInfo list(ExamplesWar examplesWar) {
        startPage();
        List<ExamplesWar> list = examplesWarService.selectExamplesWarList(examplesWar);
        return getDataTable(list);
    }

    /**
     * 导出战例数据列表
     */
    //@RequiresPermissions("business:examplewar:export")
    @Log(title = "战例数据" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, ExamplesWar examplesWar) {
        List<ExamplesWar> list = examplesWarService.selectExamplesWarList(examplesWar);
        ExcelUtil<ExamplesWar> util = new ExcelUtil<ExamplesWar>(ExamplesWar. class);
        util.exportExcel(response, list, "战例数据数据" );
    }

    /**
     * 获取战例数据详细信息
     */
    //@RequiresPermissions("business:examplewar:query")
    @GetMapping(value = "/{id}" )
    @DataSource(value = DataSourceType.SLAVE)
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(examplesWarService.selectExamplesWarById(id));
    }

    /**
     * 新增战例数据
     */
    //@RequiresPermissions("business:examplewar:add")
    @Log(title = "战例数据" , businessType = BusinessType.INSERT)
    @PostMapping
    @DataSource(value = DataSourceType.SLAVE)
    public AjaxResult add(@RequestBody ExamplesWar examplesWar) {
        return toAjax(examplesWarService.insertExamplesWar(examplesWar));
    }

    /**
     * 修改战例数据
     */
    //@RequiresPermissions("business:examplewar:edit")
    @Log(title = "战例数据" , businessType = BusinessType.UPDATE)
    @PutMapping
    @DataSource(value = DataSourceType.SLAVE)
    public AjaxResult edit(@RequestBody ExamplesWar examplesWar) {
        return toAjax(examplesWarService.updateExamplesWar(examplesWar));
    }

    /**
     * 删除战例数据
     */
    //@RequiresPermissions("business:examplewar:remove")
    @Log(title = "战例数据" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    @DataSource(value = DataSourceType.SLAVE)
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(examplesWarService.removeByIds(Arrays.asList(ids)));
    }
}
